package com.wlyuan.open.scanner.utils.enums.tenant;

import com.wlyuan.core.marker.NamedStatus;
import com.wlyuan.core.marker.NamedValue;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author lijing
 * @description 租户状态，新老系统对应关系，老系统由invalid和status确定
 */
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public enum TenantInvalidEnum implements NamedValue<Integer> {

    //禁用 无论什么状态 status
    INVALID_DISABLE(1, -1L, 0, "禁用"),
    //启用
    INVALID_ENABLED(0, 2L, 1, "启用"),
    //待审核
    INVALID_WAIT(0, 0L, 2, "待审核"),
    //待审核
    INVALID_TO_WAIT(0, 1L, 2, "待审核"),
    //已拒绝
    INVALID_REJ(0, 3L, 4, "已拒绝"),
    ;

    private final Integer invalid;
    private final Long status;
    private final Integer value;
    private final String name;

    private static final Map<String, TenantInvalidEnum> MAP = new ConcurrentHashMap<>();

    public static TenantInvalidEnum fromValue(Integer invalid, Long status) {
        if (NamedStatus.ENABLED.getValue().equals(invalid)) {
            status = -1L;
        }
        return MAP.get(invalid + ":" + status);
    }


    static {
        TenantInvalidEnum[] supplierInvalidEnum = TenantInvalidEnum.values();
        for (TenantInvalidEnum invalid : supplierInvalidEnum) {
            MAP.put(invalid.getInvalid() + ":" + invalid.getStatus(), invalid);
        }
    }
}
